import {Context}  from'koa'
import { get, post } from '../decorator/reqmethoddecorator'
 import ordAndOrdDetailService from '@/modules/orderinfo/OrdAndOrdDetailService'
 import { Controller } from '../decorator/controllerdecorator'
 import { success } from '@/common/ResResult'
 import { Orderinfo, OrderDetail } from '../modules/orderinfo/entity';
 Controller("/ordAndOrdDetailmodule")
 class OrdAndOrdDetailController{
  @post('/addordAndOrdDetail')
  async addOrdAndOrdDetail(ctx: Context) {
    // const ordAndOrdDetails = ctx.request.body;
    // 测试数据
    // todo 作业，如何解决库存问题
    const ordAndOrdDetails: Orderinfo = {
      ordertime:'2022/09/38 16:44:48',
      customerid: 1,
      orderstatus:1,
      orderDetailList:[
        {
          bookname:'三体全集(全3册)',
          bookpicname:'三体全集.png',
          bookprice: 10,
          purcharsenum: 1,
          shopcartid: 47,
        },
        {
          bookname:'云边有个小卖部',
          bookpicname:'云边有个小卖部.png',
          bookprice: 10,
          purcharsenum: 91,
          shopcartid: 48,
        },
        {
          bookname:'人生从容(在众声喧哗中保持从容(贾凭凹70岁)',
          bookpicname:'人生从容.png',
          bookprice: 9,
          purcharsenum: 180,shopcartid: 49,
        }
      ]
  }
    const lastOrderDetailLst = await ordAndOrdDetailService.submitOrder(ordAndOrdDetails);
    console.log(lastOrderDetailLst);
    ctx.body = success(lastOrderDetailLst);
  }
  @get('/findCurUsrOrdAndOrdDetail/:customerid')
  async findCurUsrOrdAndOrdDetail(ctx:Context){
    const { customerid } = ctx.params;
    const ordAndOrdDetails =  await ordAndOrdDetailService.findCurUsrOrdAndOrdDetail(customerid);
    // todo 这里也有一个conver  在21-21
    ctx.body = success(ordAndOrdDetails);
  }
  @get('/uptOrdStatusByOrdId/:orderid/:orderstatus')
  async uptOrdStatusByOrdId(ctx:Context){
    const {orderid,orderstatus = -1 }=ctx.params;
    const uptRows= await ordAndOrdDetailService.uptOrdStatusByOrdId(orderid,orderstatus);
    ctx.body = success(uptRows);
  }
 }

